<template>
  <div class="viewcontainer" v-if="dataset">
    <el-row class="view-header">
      <el-col :span="22">
        <hi-lquery
          :columnsTotal="3"
          v-bind="queryPanel"
          :target="dataset"
        ></hi-lquery>
      </el-col>
      <el-col :span="2" style="text-align: right">
        <el-button type="primary" @click="showAdd">添加</el-button>
      </el-col>
    </el-row>
    <el-row class="view-main">
      <el-table
        ref="dataTable"
        :data="dataset.data"
        height="100%"
        style="width: 100%"
        v-loading="dataset.loading"
      >
        <el-table-column type="index" width="50" />
        <el-table-column prop="FNUMBER" label="单号" width="160" />
        <el-table-column prop="FSHOPDESC" label="店铺" width="160" />
        <el-table-column prop="FSUPPLIER" label="供应商" width="200" />
        <el-table-column prop="FMONEY" label="总金额" width="140">
          <template slot-scope="scope">
            {{ formatMoney(scope.row.FMONEY) }}
          </template>
        </el-table-column>
        <el-table-column prop="FNOTE" label="备注">
          <template slot-scope="scope">
            <div class="text-truncate" :title="scope.row.FNOTE">
              {{ scope.row.FNOTE }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="FUSERID" label="创建人" width="100" />
        <el-table-column prop="FCREATEDATE" label="创建时间" width="160" />
        <el-table-column prop="FAUDIT" label="审核" width="80">
          <template slot-scope="scope">
            <audittag v-model="scope.row.FAUDIT"></audittag>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="80">
          <template slot-scope="scope">
            <el-button
              type="text"
              v-if="scope.row.FAUDIT != 0"
              title="编辑"
              size="small"
              @click="showEdit(scope, scope.row.FAUDIT)"
            >
              <i class="el-icon-edit"></i>
            </el-button>
            <el-button
              type="text"
              v-if="scope.row.FAUDIT == 0"
              title="详情"
              size="small"
              @click="showEdit(scope, scope.row.FAUDIT)"
            >
              <i class="el-icon-tickets"></i>
            </el-button>
            <el-button
              type="text"
              :disabled="scope.row.FAUDIT == 0"
              title="删除"
              size="small"
              @click="remove(scope)"
            >
              <i class="el-icon-delete"></i>
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-row>
    <el-row class="view-footer pagebar">
      <hi-pagination
        background
        :total="dataset.total"
        :target="dataset"
      ></hi-pagination>
    </el-row>
  </div>
</template>

<script>
import { HiPagination, HiLquery, utils } from "hi-ui";
import viewBase from "../../base";
import audittag from "@/views/component/audittag";
import purchaseInspectConfig from "./dataset/inspectlist";
export default {
  name: "inspectlist",
  extends: viewBase,
  components: { HiPagination, HiLquery, audittag },
  data() {
    let datasetCfg = Object.assign({}, purchaseInspectConfig, {
      action: "autoAction",
    });
    return {
      //数据桥梁
      dataBridge: new Map(),
      dataset: null,
      //数据集配置
      datasetCfg: datasetCfg,
      total: 100,
      //查询面板配置
      queryPanel: {
        fields: [
          {
            element: "el-input",
            label: "单号",
            name: "FNUMBER",
          },
          {
            label: "店铺",
            name: "FSHOPDESCID",
            element: "hi-select-grid",
            props: {
              selectOption: {
                loading: true,
                multiple: false,
                clearable: true,
                filterable: true,
                "allow-create": true,
                "collapse-tags": true,
              },
              lookup: {
                modelFile: "database/shop/dataset/ShopEntity.xml",
                label: "FDESC",
                filtername: "FDESC",
                tableprops: {
                  // border:true,
                  hideRowBorder: true,
                  stripe: true,
                  "show-header": false,
                  //fit:false,
                  size: "mini",
                  "max-height": 400,
                },
                returnFields: {
                  FSHOPDESCID: "FNUMBER",
                },
                columns: [
                  {
                    name: "FDESC",
                    label: "通用名称",
                  },
                ],
              },
            },
          },
          {
            label: "供应商",
            name: "FSUPPLIER",
            element: "hi-select-grid",
            props: {
              selectOption: {
                loading: true,
                multiple: false,
                clearable: true,
                filterable: true,
                "allow-create": true,
                "collapse-tags": true,
              },
              lookup: {
                modelFile: "database/supplier/dataset/SupplierEntity.xml",
                // label: "FDESC",
                // filtername: "FCOMMON",
                filternames: [
                  {
                    name: "FDESC",
                  },
                  {
                    name: "FPINYIN",
                    // operate: "like",
                  },
                  {
                    name: "FJIANPIN",
                  },
                ],
                active: false,
                tableprops: {
                  // border:true,
                  hideRowBorder: true,
                  stripe: true,
                  "show-header": false,
                  //fit:false,
                  size: "mini",
                  "max-height": 400,
                  white_space_nowrap: true,
                },
                returnFields: {
                  FSUPPLIER: "FDESC",
                  // FSHOPDESCID: "FNUMBER",
                },
                columns: [
                  {
                    name: "FDESC",
                    label: "通用名称",
                  },
                ],
              },
            },
          },
        ],
      },
    };
  },
  model: {
    prop: "value",
    event: "valuechange",
  },
  props: {
    value: {
      type: Object,
    },
  },

  computed: {},
  watch: {},
  methods: {
    formatMoney(val) {
      return utils.number.format(val, "￥");
    },
    showAdd() {
      this.openByPath("/purchase/inspect/detail", null, {
        title: "添加验收入库",
      });
    },
    showEdit(data, detail) {
      this.openByPath(
        "/purchase/inspect/detail",
        { id: data.row.FID },
        {
          title: "【" + data.row.FNUMBER + (detail == 0 ? "】详情" : "】编辑"),
          target: "_blank",
        }
      );
    },
    remove(data) {
      this.$confirm("确定要删除【" + data.row.FNUMBER + "】", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let saveHelper = this.createSaveHelper(this.dataset.modelFile);
          saveHelper.remove(data.row);
          saveHelper.save().then((res) => {
            this.dataset.reload();
            this.$message({
              type: "success",
              message: "删除成功!",
            });
          });
          /* this.dataset.remove(data.row);

          this.dataset.save().then((res) => {
            this.$message({
              type: "success",
              message: "删除成功!",
            });
          }); */
        })
        .catch(() => {});
    },
  },
  mounted() {
    this.dataset = this.createDataSet(this.datasetCfg); //this.$dsContainer.createDataSet(this.datasetCfg);
    this.dataBridge.set(this.dataset, ["dataTable"]);
  },
};
</script>
<style rel="stylesheet/scss" lang="scss" scope>
</style>

